define('controllers/subpage', function (require, exports, module) {
	"use strict";

	var fnGlobalUrl = require[require.toUrl ? 'toUrl' : 'resolve'];
	var $window = $(window),
		$document = $(document);
		var m_superslide = require('jquery.superslide')

	/* ************************************************************ */
	var m_Subpage = { /* 定义一个首页对象 */
		createNew: function () {
			if(!(window.basePage) || typeof(window.basePage.createNew) !=='function'){
				window.basePage={};
				window.basePage.createNew=function(){
					return {};
				}
			}
			var $internal = window.basePage.createNew();
			/* code here for example */
			$internal.Banner = null;

			$internal.init = function () { /* 页面类的初始化， 向$internal上绑定功能对象， 如下绑定 Banner 对象 */
				/*code here 如下： */
				this.News = new $News();
				this.Details = new $Details();
				this.BigPicture = new $BigPicture();
				this.score = new $score();
			};
			
			/*===============资讯频道首页头条轮播===============*/
			var $News = new Class({
				initialize: function () {
					this._init();
				}
			});
			$News.extend({
				_init: function () {
					this.isAppear = false;
					this.mySwiper = null;
					this.myTimers = undefined;
					this._initDom();
				},
				_initDom: function () {
						var _this = this;
					_this.newsNode = $('.J_latest_scroll');
				},
				appear: function () {
					var _this = this;
					_this.newsNode.slide({
						titCell:".latest-scroll-hd li",
						mainCell:".latest-scroll-bd ul",
						effect:"top",
						autoPlay:true,
						triggerTime:0
					});
					if($('.J_tnews').length>0){
						$('.n-choice-item').hoverIntent({
							over: function(){
								$('.n-choice-item').removeClass('active');
								$(this).addClass('active');
							}
						});

					}
					if($('.J_anotherBatch').length>0){
						var ab_flag = 0;
						$('.J_anotherBatch').on('click', '.J_anotherBatch_btn', function() {
							var _the = $(this).parents('.J_anotherBatch'),
									dom = _the.find('.J_dom').html(),
									ajaxUrl = _the.attr('ajaxUrl'),
									type = _the.attr('dataTyep');

							if(!ab_flag){
								ab_flag = 1;
								$.ajax({
									url: ajaxUrl,
									type: 'POST'
								})
								.done(function(res) {
									res = eval(res);
									if(res.code==200){
										var list = res.data.list;
										if(type=="news"){
											for(var i=0;i<list.length;i++){
												var newHtml = $('<div></div>');
												newHtml.html(dom);
												newHtml.find('.rec-link').attr('href',list[i].url);
												newHtml.find('.rec-pic img').attr('src',list[i].img);
												newHtml.find('.rec-title').text(list[i].title);
												newHtml.find('.rec-desc').text(list[i].text);
												if(i==0){
													_the.find('.J_anotherBatch_list').html(newHtml);
												}else{
													_the.find('.J_anotherBatch_list').append(newHtml);
												}
											}
										}else{
											for(var i=0;i<list.length;i++){
												var newHtml = $('<div></div>');
												newHtml.html(dom);
												newHtml.find('.imgbox img').attr('src',list[i].img);
												newHtml.find('a').attr('href',list[i].url);
												newHtml.find('.school_title a').text(list[i].title);
												newHtml.find('.school_resume').text(list[i].text);
												newHtml.find('.school_address').html('昆明市<a href="' + list[i].areaUrl + '">'+list[i].area+'</a>'+list[i].address);
												newHtml.find('.scorebox strong').text(list[i].fraction);
												if(list[i].hot==0||list[i].hot=='0'){
													newHtml.find('.hotlab').remove();
												}
												if(i==0){
													_the.find('.J_anotherBatch_list').html(newHtml);
												}else{
													_the.find('.J_anotherBatch_list').append(newHtml);
												}
											}
										}
									}
								})
								.fail(function() {
								})
								.always(function() {
									layer.closeAll('loading');
									ab_flag = 0;
								});
							}
						});
					}
				},
			});
			
			/*===============学校展示详情图片轮播===============*/
			var $Details = new Class({
				initialize: function () {
					this._init();
				}
			});
			$Details.extend({
				_init: function () {
					this.isAppear = false;
					this.mySwiper = null;
					this.myTimers = undefined;
					this._initDom();
				},
				_initDom: function () {
						var _this = this;
					_this.detailsNode = $('.J_school_pic_scrool');
				},
				appear: function () {
					var _this = this;
					_this.detailsNode.slide({
						mainCell:".school-pic-bd ul",
						autoPage:true,
						effect:"left",
						autoPlay:true,
						vis:3
					});
				},
			});

			var $BigPicture = new Class({
				initialize: function () {
					this._init();
				}
			});
			
			$BigPicture.extend({
				_init: function () {
					this.isAppear = false;
					this.mySwiper = null;
					this.myTimers = undefined;
					this._initDom();
				},
				_initDom: function () {
						var _this = this;
				},
				appear: function () {
					var _this = this,
							backText = '';
					if($('.J_showAll').length>0){
						$('.J_showAll').on('click',function(){
							var _the = $(this);
							if(_the.hasClass('open')){
								_the.removeClass('open').html(backText);
								$('.s-style-items').css('height','');
							}else{
								backText = _the.html();
								_the.addClass('open').html('收起 <i class="fa fa-angle-up"></i>');
								$('.s-style-items').css('height','auto');
							}
						});
					}
					$('body').on('click','.preview',function(){
						var _the = $(this),
								group = _the.attr('data-group'),
								layerArray = [],
								imgOn = 0;
						$('[data-group="' + group + '"]').each(function(index,el){
							layerArray[index]={};
							layerArray[index].url = $(el).attr('data-bigimg')||$(el).attr('src');
							layerArray[index].name = $(el).attr('alt')||'';
							if(_the==$(el)){
								imgOn = index;
							}
						});
						_this.foundLayer(layerArray,imgOn);
					});
				},
				foundLayer: function(data,on){
					var _this = this,
							newHtml = '',
							maxHeight = parseInt($(window).height()) - 200,
							slideList = $('<ul></ul>'),
							newSlideDom = $('<div></div>');
							newSlideDom.append('<div class="slideBox"></div>');
							newSlideDom.find('.slideBox').append('<div class="bd"></div>');
							newSlideDom.find('.slideBox').append('<a class="prev fa fa-angle-left" href="javascript:void(0)"></a>');
							newSlideDom.find('.slideBox').append('<a class="next fa fa-angle-right" href="javascript:void(0)"></a>');
							on = on + 1;
					for(var i=0;i<data.length;i++){
						var newLi = $('<li><p></p><img></li>');
						newLi.find('p').text(data[i].name);
						newLi.find('img').attr('src',data[i].url);
						slideList.append(newLi);
					}
					newSlideDom.find('.slideBox').css('height',maxHeight+'px');
					newSlideDom.find('.bd').html(slideList);
					newSlideDom.find('img').css('max-height',maxHeight+'px');
					newSlideDom.find('a').css('line-height',maxHeight+'px');
					console.log(maxHeight);

					layer.open({
					  type: 1,
					  skin: 'layui-bigImg', //样式类名
					  title: false,
					  closeBtn: 1, //不显示关闭按钮
					  anim: 2,
					  shadeClose: true, //开启遮罩关闭
						maxWidth: 1180,
						maxHeight: maxHeight,
					  content: newSlideDom.html(),
					  success: function(layero, index){
					    console.log(layero, index);
					    layero.find('.slideBox').slide({
								mainCell:".bd ul",
								effect:"leftLoop",
								defaultIndex: on
							});
					  }
					});
				}
			});

			var $score = new Class({
				initialize: function () {
					this._init();
				}
			});
			
			$score.extend({
				_init: function () {
					this.isAppear = false;
					this.mySwiper = null;
					this.myTimers = undefined;
					this._initDom();
				},
				_initDom: function () {
						var _this = this;
				},
				appear: function () {
					var _this = this;
					$('.J_score').on('click','.J_star',function(){
						var num = $(this).index(),
								_the = $(this).parents('.J_score');
						_the.find('.J_star').removeClass('active').each(function(index,el){
							if(index<=num){
								$(this).addClass('active');
							}
						});
						_the.next('input[type="hidden"]').val(num);
					});
					//星级评分的hover
					if($('.J_score').length>0){
						$('.J_score .J_star').hover(function(){
							  var _this=$(this);
								var num = $(this).index();
						     for(var i=0; i<=num;i++){
									 _this.parent('.J_score').find('.J_star').eq(i).addClass('on');
								 }
//					
						 	},function(){
						    	var _this=$(this);
							_this.parent('.J_score').find('.J_star').removeClass('on');
							});
						
						
					}
					
					
					
					
					
				
				}
			});

			return $internal; //返回对象
		}


	};
	exports.run = function () {
		var SUBPAGE = m_Subpage.createNew();
		SUBPAGE.init();
		$document.ready(function () {
			SUBPAGE.News.appear();
			SUBPAGE.Details.appear();
			if($('.preview').length>0){
				SUBPAGE.BigPicture.appear();
			}
			if($('.J_score').length>0){
				SUBPAGE.score.appear();
			}
		});


	};
});
